package com.sneakxy.mybase4j.platform.service;

import com.alibaba.dubbo.config.annotation.Reference;

import com.sneakxy.mybase4j.base.service.BaseService;

import com.sneakxy.mybase4j.platform.beans.Permission;

import com.sneakxy.mybase4j.platform.provider.IPermissionProvider;

import com.sneakxy.mybase4j.platform.service.IPermissionService;
import com.sneakxy.mybatis.commons.repository.query.domain.CriteriaBuilder;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.stereotype.Service;

/**
 * 
 * @author 潜行的青衣
 * @see
 */
@Service
public class PermissionService extends BaseService<Permission, String, IPermissionProvider> implements IPermissionService {

	@Reference(version = "1.0.0")
	@Autowired(required = false)
	@Qualifier("permissionProvider")
	private IPermissionProvider provider;

	@Override
	public IPermissionProvider getProvider() {
		return this.provider;
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.IPermissionService#findAllByParentId(boolean)
	 */
	@Override
	public List<Permission> findAllByParentId(boolean hasChildren) {
		return this.getProvider().findAllByParentId(hasChildren);
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.IPermissionService#countByParentId(java.lang.String)
	 */
	@Override
	public long countByParentId(String parentId) {
		CriteriaBuilder<Permission> builder = new CriteriaBuilder<Permission>(Permission.class);
		builder.andEq("parentId", parentId);
		return this.getProvider().count(builder.build());
	}
	
}
